//截取汉字
//substr
//全选 全不选
function sall(selectallid,checkboxname){
	 var selecta=document.getElementById(selectallid);
	 var checkboxs=document.getElementsByName(checkboxname);
	 for(var i=0;i<checkboxs.length;i++){
		 checkboxs[i].checked=selecta.checked; 
	 }
}
//检测是否已经有选择要删除的项目
function checkselectdelitem(checkboxname,url){
	var aryId=[];
	var checkboxs=document.getElementsByName(checkboxname);
	for(var i=0;i<checkboxs.length;i++){
	   if(checkboxs[i].checked) aryId.push(checkboxs[i].value);	
	}
	if(aryId.length>0){
	   if(confirm("你确定要执行此操作吗?"))	
	     location.href=url+"/item_ids/"+aryId.join(",");
	}else{
	    alert("请选择项目!");
	}
}  
 //获取当前日期 时间 星期
function datetimeweek(){
  var now=new Date();
  var year=now.getYear();
  var month=now.getMonth();
  var date=now.getDate();
  var day=now.getDay();
  var hour=now.getHours();
  var minu=now.getMinutes();
  var sec=now.getSeconds();
  var week;
  month=month+1;
  if(month<10) month="0"+month;
  if(date<10) date="0"+date;
  if(hour<10) hour="0"+hour;
  if(minu<10) minu="0"+minu;
  if(sec<10) sec="0"+sec;
  var arr_week=new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
  week=arr_week[day];
  var time="";
  time=year+"年"+month+"月"+date+"日"+" "+hour+":"+minu+":"+sec+" "+week;
  return time;
}
//模拟获取GET值的JavaScript
//使用 var GET = query_get(); var value=GET['u'];
function query_get(){
  var urlt = window.location.href.split("?");
  var gets = urlt[urlt.length-1].split("&");
  var location_get_vars = new Array();
  for(var i=0;i<gets.length;i++){
    var get = gets[i].split("=");
    eval("location_get_vars['" + get[0] + "'] = '" + unescape(get[1]) + "';");
  }
  return location_get_vars;
} 
//检测表单 当表单所有元素都需要检测的时候  并且有title属性
function checkform(theform){
   for(var i=0;i<theform.length;i++){
	      if(theform.elements[i].value==''){
			  alert(theform.elements[i].title+"不能为空");
			  theform.elements[i].focus();
			  return false;
		  }
   }
}
//限制文本框输入文字个数
function gbcount(message,total,used,remain){
  var max;
  max = total.value;
  if (message.value.length > max) {
     message.value = message.value.substring(0,max);
     used.value = max;
     remain.value = 0;
     alert(message.title+"不能超过"+total.value+"个字!");
  }else{
     used.value = message.value.length;
     remain.value = max - used.value;
  }
}
//使用范例
//<div align="left">
//        <textarea name="notice" cols="30" rows="5" id="notice" title="网站公告" style="height:150px; overflow-y:visible;width:400px;word-break:break-all" tabindex="11" onKeyDown="gbcount(this.form.notice,this.form.total,this.form.used,this.form.remain);" onKeyUp="gbcount(this.form.notice,this.form.total,this.form.used,this.form.remain);"><?php echo $data[0]["notice"];?></textarea>
//     <br>最多字数：
//<input disabled maxLength="4" name="total" size="3" value="15" style="border:none; background-color:#FFFFFF">
//已用字数：
//<input disabled maxLength="4" name="used" size="3" value="0" style="border:none; background-color:#FFFFFF">
//剩余字数：
//<input disabled maxLength="4" name="remain" size="3" value="15" style="border:none; background-color:#FFFFFF"></div>
	
function empty(v){
	  switch (typeof v){ 
         case 'undefined' : return true; 
         case 'string' : if(trim(v).length == 0) return true; break; 
         case 'boolean' : if(!v) return true; break; 
         case 'number' : if(0 === v) return true; break; 
         case 'object' : 
            if(null === v) return true; 
            if(undefined !== v.length && v.length==0) return true; 
            for(var k in v){return false;} return true; 
            break; 
     } 
     return false; 
}
function trim(s) {
   return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
}
//加载js 类似与jquery loadscript  异步加载js
function LoadJS(fileUrl) { 
    var oHead = document.getElementsByTagName('HEAD').item(0); 
    var oScript= document.createElement("script"); 
    oScript.type = "text/javascript"; 
    oScript.src=fileUrl ; 
    oHead.appendChild( oScript); 
} 
//LoadJS( "a.js" ); 

//同步加载js
function GetHttpRequest() { 
   if ( window.XMLHttpRequest ) // Gecko 
        return new XMLHttpRequest() ; 
    else if ( window.ActiveXObject ) // IE 
        return new ActiveXObject("MsXml2.XmlHttp") ; 
} 
function AjaxPage(sId, url){ 
    var oXmlHttp = GetHttpRequest() ; 
    oXmlHttp.OnReadyStateChange = function(){ 
        if (oXmlHttp.readyState == 4 ) { 
            if (oXmlHttp.status == 200) { 
               IncludeJS(sId,url,oXmlHttp.responseText ); 
            }else{ 
               alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ; 
            } 
        } 
    } 
    oXmlHttp.open('GET', url, true); 
    oXmlHttp.send(null); 
} 

function IncludeJS(sId, fileUrl, source) { 
       if ( ( source != null ) && ( !document.getElementById( sId ) ) ){ 
       var oHead = document.getElementsByTagName('HEAD').item(0);
       var oScript = document.createElement( "script" ); 
       oScript.language = "javascript"; 
       oScript.type = "text/javascript"; 
       oScript.id = sId; 
       oScript.defer = true; 
       oScript.text = source; 
       oHead.appendChild( oScript ); 
    } 
} 
//AjaxPage("scrA","a.js"); 
//alert( "主页面动态加载JS脚本。"); 
//alert( "主页面动态加载a.js并取其中的变量：" + ljw ); 
//同步加载js
//兼容FF 加入收藏夹和设为首页
function AddFavorite(sURL, sTitle) 
{ 
    try 
    { 
        window.external.addFavorite(sURL, sTitle); 
    } 
    catch (e) 
    { 
        try 
        { 
            window.sidebar.addPanel(sTitle, sURL, ""); 
        } 
        catch (e) 
        { 
            alert("加入收藏失败，请使用Ctrl+D进行添加"); 
        } 
    } 
} 
function SetHome(obj,vrl){ 
        try{ 
                obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl); 
        } 
        catch(e){ 
                if(window.netscape) { 
                        try { 
                                netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
                        } 
                        catch (e) { 
                                alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将 [signed.applets.codebase_principal_support]的值设置为'true',双击即可。"); 
                        } 
                        var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch); 
                        prefs.setCharPref('browser.startup.homepage',vrl); 
                 } 
        } 
} 
//示例
//<a onclick="AddFavorite(window.location.href,document.title)">加入收藏</a> 
//<a onclick="SetHome(this,window.location.href)">设为首页</a> 

  